<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: box_manager.php 21 2013-09-21 11:53:18Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 21 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:53:18 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');

$languages = get_languages();

if((isset($_POST['save'])) && ($_POST['save'] == 'file_box')) {
	$box_position = $_POST['box_position'];
	$box_sort_id = $_POST['box_sort_id'];
	$box_status = $_POST['box_status'];
	$box_name_status = $_POST['box_name_status'];
	$name = $_POST['name'];
	$in_blog = $_POST['in_blog'];
	$group_ids = '';
	if(isset($_POST['groups']))
		foreach($_POST['groups'] AS $b)
			$group_ids .= 'c_'.$b."_g,";
	
	$sql = array('position' => $box_position,
				'sort_id' => $box_sort_id,
				'status' => $box_status,
				'group_ids' => $group_ids,
				'in_blog' => $in_blog);
	
	$db->db_perform(TABLE_BOXES, $sql, 'update', "box_name = ".$db->db_prepare($name));

	foreach($languages AS $lang) {
		$title = $_POST['box_name_'.$lang['id']];
		
		$checkData = $db->db_query("SELECT status FROM ".TABLE_BOXES_NAMES." WHERE language_id = '".$lang['id']."' AND box_name = ".$db->db_prepare($name));
		if($checkData->_numOfRows)
			$db->db_query("UPDATE ".TABLE_BOXES_NAMES." SET box_title = '".trim($title)."', status = ".$box_name_status." WHERE language_id = '".$lang['id']."' AND box_name = ".$db->db_prepare($name));
		else
			$db->db_query("INSERT INTO ".TABLE_BOXES_NAMES." (box_title, status, language_id, box_name) VALUES ('".trim($title)."', ".$box_name_status.", '".$lang['id']."', ".$db->db_prepare($name).") ");
	}

	$border_color = $_POST['border_color'];
	$background_content = $_POST['background_content'];
	$color_content = $_POST['color_content'];
	$background_head = $_POST['background_head'];
	$color_head = $_POST['color_head'];

	$style_query = $db->db_query("SELECT id FROM ".TABLE_BOXES_STYLES." WHERE box_name = ".$db->db_prepare($name));

	if($style_query->_numOfRows > 0) {
		$sql_data_array = array('border_color' => $border_color,
								'background_content' => $background_content,
								'color_content' => $color_content,
								'background_head' => $background_head,
								'color_head' => $color_head);
		$db->db_perform(TABLE_BOXES_STYLES, $sql_data_array, 'update', "box_name = ".$db->db_prepare($_POST['name']));

	} else {
		$sql_data_array = array('box_name' => $name,
								'border_color' => $border_color,
								'background_content' => $background_content,
								'color_content' => $color_content,
								'background_head' => $background_head,
								'color_head' => $color_head);
		$db->db_perform(TABLE_BOXES_STYLES, $sql_data_array);
	}

	redirect(href_link('box_manager.php'));

} elseif(isset($_GET['set_flag']) && (!empty($_GET['set_flag']))) {
	$box_status = $_GET['status'];
	$db_box = $db->db_query("UPDATE ".TABLE_BOXES." SET status = '".$box_status."' WHERE box_name = '".$_GET['set_flag']."'  ");

	redirect(href_link('box_manager.php')); exit();

} elseif(isset($_GET['set_name_flag']) && (!empty($_GET['set_name_flag']))) {
	$box_status = $_GET['status'];
	$db_box = $db->db_query("UPDATE ".TABLE_BOXES_NAMES." SET status = '".$box_status."' WHERE box_name = '".$_GET['set_name_flag']."'  ");

	redirect(href_link('box_manager.php'));

} elseif(isset($_GET['delete']) && (!empty($_GET['delete']))) {
	if(strstr($_GET['delete'], 'categories_') && is_numeric(substr($_GET['delete'], 11))) {
		$nr = substr($_GET['delete'], 11);
		$check = $db->db_query("SELECT categories_id WHERE num = '".$nr."' LIMIT 1");
		if($check->_numOfRows){
			$message_stack->add_session('Mit dieser Box sind noch Kategorien verbunden, Sie kann nicht gelöscht werden!', 'warning');
			redirect(href_link('box_manager.php'));
		}
	}
	
	$db->db_query("DELETE FROM ".TABLE_BOXES." WHERE box_name = '".$_GET['delete']."'");
	$db->db_query("DELETE FROM ".TABLE_BOXES_NAMES." WHERE box_name = '".$_GET['delete']."' ");
	$db->db_query("DELETE FROM ".TABLE_CM_FILE_FLAGS." WHERE file_flag_name = '".$_GET['delete']."' ");
	
	redirect(href_link('box_manager.php'));

} elseif((isset($_POST['save'])) && (($_POST['save'] == 'new_box') || $_POST['save'] == 'edit_new_box')) {
	$group_ids = '';
	if(isset($_POST['groups']))
		foreach($_POST['groups'] AS $b)
			$group_ids .= 'c_'.$b."_g,";

	$double_check = $db->db_query("SELECT box_name FROM ".TABLE_BOXES." WHERE box_name = '".$_POST['box_int_name']."'");

	if($_POST['save'] == 'new_box') {
		
		if(!$double_check->_numOfRows) {
			$getNextID = $db->db_query("SELECT file_flag FROM ".TABLE_CM_FILE_FLAGS." ORDER BY file_flag DESC LIMIT 1");
	
			$db->db_query("INSERT INTO ".TABLE_CM_FILE_FLAGS." VALUES ('".($getNextID->fields['file_flag']+1)."', ".$db->db_prepare($_POST['box_int_name']).")");
	
			$sql_data_array = array ('id' => '',
									'box_name' => $_POST['box_int_name'],
									'position' => $_POST['box_position'],
									'sort_id' => $_POST['box_sort_id'],
									'in_blog' => $_POST['box_in_blog'],
									'status' => $_POST['box_status'],
									'group_ids' => $group_ids,
									'box_type' => 'database',
									'file_flag' => $getNextID->fields['file_flag']+1);
			$db->db_perform(TABLE_BOXES, $sql_data_array);

		} else {
			$message_stack->add_session('Der Name einer Box darf nicht mehr als einmal vorkommen', 'error');
			redirect(href_link('box_manager.php', getMenuID('box_manager').'&action=new_box'));
		}
			

	} elseif($_POST['save'] == 'edit_new_box') {
		$sql_data_array = array ('position' => $_POST['box_position'],
								'sort_id' => $_POST['box_sort_id'],
								'in_blog' => $_POST['box_in_blog'],
								'box_type' => 'database',
								'group_ids' => $group_ids,
								'status' => $_POST['box_status']);
		$db->db_perform(TABLE_BOXES, $sql_data_array, 'update', 'box_name = \''.$_POST['box_int_name'].'\'');

	}

	foreach($languages as $lang) {
		if($_POST['save'] == 'new_box') {
			if(!$double_check->_numOfRows) {
				$insert_data_array = array ('box_name' => $_POST['box_int_name'],
											'box_title' => $_POST['box_title_'.$lang['id']],
											'box_desc' => stripslashes($_POST['new_box_'.$lang['id']]),
											'language_id' => $lang['id'],
											'status' => $_POST['box_name_status']);
	
				$db->db_perform(TABLE_BOXES_NAMES, $insert_data_array);
			}

		} elseif($_POST['save'] == 'edit_new_box') {
			$update_data_array = array ('box_title' => $_POST['box_title_'.$lang['id']],
										'box_desc' => stripslashes($_POST['new_box_'.$lang['id']]));
										#print_r($update_data_array); exit; 
			$db->db_perform(TABLE_BOXES_NAMES, $update_data_array, 'update', 'box_name = \''.$_POST['box_int_name'].'\' AND language_id = \''.$lang['id'].'\'');
		}
	}
	
	$border_color = $_POST['border_color'];
	$background_content = $_POST['background_content'];
	$color_content = $_POST['color_content'];
	$background_head = $_POST['background_head'];
	$color_head = $_POST['color_head'];

	$style_query = $db->db_query("SELECT id FROM ".TABLE_BOXES_STYLES." WHERE box_name = ".$db->db_prepare($_POST['box_int_name']));

	if($style_query->_numOfRows > 0) {
		$sql_data_array = array('border_color' => $border_color,
								'background_content' => $background_content,
								'color_content' => $color_content,
								'background_head' => $background_head,
								'color_head' => $color_head);
		$db->db_perform(TABLE_BOXES_STYLES, $sql_data_array, 'update', "box_name = ".$db->db_prepare($_POST['box_int_name']));

	} else {
		$sql_data_array = array('box_name' => $_POST['box_int_name'],
								'border_color' => $border_color,
								'background_content' => $background_content,
								'color_content' => $color_content,
								'background_head' => $background_head,
								'color_head' => $color_head);
		$db->db_perform(TABLE_BOXES_STYLES, $sql_data_array);
	}
	
	$message_stack->add_session('Die Daten der Box wurden gespeichert', 'success');
	if(isset($_POST['apply_box']))
		redirect(href_link('box_manager.php', getMenuID('box_manager').'&action=edit_new_box&name='.$_POST['box_int_name']));
	else
		redirect(href_link('box_manager.php'));

} elseif(isset($_POST['filter']) && ($_POST['filter'] == 'boxes')) {
	$sql_where = '';
	$sql_order_by = '';

	if($_POST['name_int']=='asc')
		$sql_order_by = " ORDER BY b.box_name ASC";
	elseif($_POST['name_int']=='desc')
		$sql_order_by = " ORDER BY b.box_name DESC";
	
	if($_POST['box_status']=='on')
		$sql_where .= " AND b.status = '1'";
	elseif($_POST['box_status']=='off')
		$sql_where .= " AND b.status = '0'";

	if($_POST['name']=='asc')
		$sql_order_by = " ORDER BY bn.box_title ASC";
	elseif($_POST['name']=='desc')
		$sql_order_by = " ORDER BY bn.box_title DESC";

	if(!empty($_POST['position']))
		$sql_where .= " AND b.position = '".$_POST['position']."'";

	if($_POST['box_name']=='on')
		$sql_where .= " AND bn.status = '1'";
	elseif($_POST['box_name']=='off')
		$sql_where .= " AND bn.status = '0'";

} elseif(isset($_GET['do']) && $_GET['do'] == 'duplicate_cat') {
	
	$get = $db->db_query("SELECT *, MAX(num) AS next_cat FROM ".TABLE_BOXES." WHERE box_name LIKE 'categories%'");
	$nr = $get->fields['next_cat']+1;
	
	$cat_box_array = array('box_name' => 'categories_'.$nr,
							'position' => $get->fields['position'],
							'sort_id' => $get->fields['sort_id'],
							'status' => $get->fields['status'],
							'box_type' => 'file',
							'num' => $nr,
							'group_ids' => $get->fields['group_ids']);
	$db->db_perform(TABLE_BOXES, $cat_box_array);

	foreach($languages AS $lang) {
		$insert_data_array = array('box_name' => 'categories_'.$nr,
									'box_title' => 'Kategorien '.$nr,
									'box_desc' => '',
									'language_id' => $lang['id'],
									'status' => '1');
		$db->db_perform(TABLE_BOXES_NAMES, $insert_data_array);
	}
	$message_stack->add_session('Es wurde eine weitere Kategoriebox angelegt, Sie kann nun bearbeitet werden', 'success');
	redirect(href_link('box_manager.php'));
}

if($sql_order_by =='')
		$sql_order_by = " ORDER BY position,sort_id ASC";

$pos = $db->db_query("SELECT id, position_name FROM ".TABLE_BOXES_POSITION." ORDER BY id");
if(!isset($_GET['action']))
	$position_array = array (array ('id' => '', 'text' => '------'));
while(!$pos->EOF) {
	$position_array[] = array ('id' => $pos->fields['position_name'], 'text' => $pos->fields['position_name']);
	$pos->MoveNext();
}

$status = array (array ('id' => '0', 'text' => '----'));
$status[] = array ('id' => 'on', 'text' => YES);
$status[] = array ('id' => 'off', 'text' => NO);

$box_name = array (array ('id' => '', 'text' => '-----------'));
$box_name[] = array ('id' => 'asc', 'text' => 'Alphabet A-Z');
$box_name[] = array ('id' => 'desc', 'text' => 'Alphabet Z-A');

if(!isset($_GET['action']))
	require(DIR_FS_ADMIN.DIR_WS_INCLUDES.'xajax/xajax.boxen_manager.php');

require(DIR_WS_INCLUDES.'metatag.php'); 
if(!empty($xajax))
	$xajax->printJavascript();
?>
<link type="text/css" rel="stylesheet" href="includes/javascript/miniColor/jquery.miniColors.css" />
<script type="text/javascript" src="includes/javascript/miniColor/jquery.miniColors.js"></script>
<script type="text/javascript" src="includes/javascript/jquery.fixedTableHeader.js"></script>
<script type="text/javascript">
	$(function(){$(".multiple").miniColors();$('.dataTable').fixedtableheader();});
</script>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
	<table class="outerTable">
		<tr>
			<td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
				<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
			</td>
				<td class="boxCenter" valign="top">
					<table border="0" width="100%" cellspacing="0" cellpadding="0">
						<tr>
							<td colspan="3">
								<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
									<tr>
										<td class="pageHeading">Boxen Manager</td>
									</tr>
								</table>
							</td>
						</tr>
						<tr>
							<td align="left">
								<?php if((!isset($_GET['action'])) && ($_GET['action'] != 'edit_box') ) { ?>
									<?php echo draw_form('sort_boxes', 'box_manager.php'); ?>
										<table cellpadding="8" cellspacing="8" width="100%">
											<tr>
												<td><strong>Filter</strong></td>
												<td>Box Name: <?php echo draw_pull_down_menu('name',$box_name,$_POST['name'],'onchange="this.form.submit();" style="width:auto"'); ?></td>
												<td>interne Bez.: <?php echo draw_pull_down_menu('name_int',$box_name,$_POST['name_int'],'onchange="this.form.submit();" style="width:auto"'); ?></td>
												<td>Position: <?php echo draw_pull_down_menu('position', $position_array,$_POST['position'],'onchange="this.form.submit();" style="width:auto"'); ?></td>
												<td>Box aktiv: <?php echo draw_pull_down_menu('box_status',$status,$_POST['box_status'],'onchange="this.form.submit();" style="width:auto"'); ?></td>
												<td>Name aktiv: <?php echo draw_pull_down_menu('box_name',$status,$_POST['box_name'],'onchange="this.form.submit();" style="width:auto"'); ?></td>
												<td align="center" style="padding:8px 0"><a class="button" href="<?php echo href_link('box_manager.php', 'action=new_box&'.getMenuID('boxen_manager')); ?>">neue Box</a></td>
											</tr>
										</table>
										<input type="hidden" name="filter" value="boxes" />
									</form>
									<table class="dataTable" width="100%">
										<tr class="dataTableHeadingRow">
											<th class="dataTableHeadingContent" height="20" width="30">&nbsp;</th>
											<th class="dataTableHeadingContent" align="left" height="20">
												Boxen Name
											</th>
											<th class="dataTableHeadingContent" align="left" height="20">interne Bezeichnung</th>
											<th class="dataTableHeadingContent" align="center" height="20">Position <?php echo get_help('3','Position im Template'); ?></th>
											<th class="dataTableHeadingContent" align="center" height="20">Sortierung</th>
											<th class="dataTableHeadingContent" align="center" height="20">Box Status</th>
											<th class="dataTableHeadingContent" align="center" height="20">Titel Status</th>
											<th class="dataTableHeadingContent" align="center" height="20">Typ</th>
										</tr>
										<?php
											$box = $db->db_query("SELECT
																		b.id AS bid,
																		bn.id AS bnid,
																		b.box_name,
																		b.position,
																		b.sort_id,
																		b.box_type,
																		b.status AS box,
																		bn.status AS bname,
																		bn.box_title
																	FROM
																		".TABLE_BOXES." b,
																		".TABLE_BOXES_NAMES." bn
																	WHERE
																		bn.box_name = b.box_name
																	AND
																		bn.language_id = '".$_SESSION['languages_id']."'
																		".$sql_where."
																		".$sql_order_by." ");

										$i=1;
										while(!$box->EOF) {
											if($i % 2 == 0) $f = 'dataTableRow';
											else $f = '';
											?>
											<tr class="<?php echo $f; ?>" onmouseover="this.className='dataTableRowOver';this.style.cursor='pointer'" onmouseout="this.className='<?php echo $f ?>'">
												<td align="center">
													<?php
														if($box->fields['box_type'] == 'database')
															echo '<a href="'.href_link('box_manager.php','action=edit_new_box&name='.$box->fields['box_name']).'">'.image(DIR_WS_IMAGES.'icon_edit.gif').'</a>';
														else
															echo '<a href="'.href_link('box_manager.php','action=edit_box&name='.$box->fields['box_name']).'">'.image(DIR_WS_IMAGES.'icon_edit.gif').'</a>';
													?>
												</td>
												<td>
													<?php echo '<strong>'.$box->fields['box_title'].'</strong>'; ?>
												</td>
												<td>
													<?php echo $box->fields['box_name']; ?>
												</td>
												<td align="center" valign="middle">
													<?php echo $box->fields['position'] ?>
												</td>
												<td align="center" valign="middle">
													<?php echo $box->fields['sort_id'] ?>
												</td>
												<td align="center" valign="middle" id="box_bs_<?php echo $box->fields['bid']; ?>">
													<?php
														if($box->fields['box'] == 1) {
															$s = 1;
															$desc = BOX_DEACTIVATE;
														} else {
															$s = 0;
															$desc = BOX_ACTIVATE;
														}	
													?>
													<img onclick="xajax_setFlag(<?php echo $box->fields['bid']; ?>, 'bs', <?php echo $s ?>)" src="images/icons/status_<?php echo $box->fields['box'] ?>.png" alt="" title="<?php echo $desc ?>" />
												</td>
												<td class="last" align="center" valign="middle" id="box_bn_<?php echo $box->fields['bnid']; ?>">
													<?php
														if($box->fields['bname'] == 1) {
															$s = 1;
															$desc = BOX_DEACTIVATE;
														} else {
															$s = 0;
															$desc = BOX_ACTIVATE;
														}														
													?>
													<img onclick="xajax_setFlag(<?php echo $box->fields['bnid']; ?>, 'bn', <?php echo $s ?>)" src="images/icons/status_<?php echo $box->fields['bname'] ?>.png" alt="" title="<?php echo $desc ?>" />
												</td>
												<td class="last" align="center">
													<?php
														if($box->fields['box_type'] == 'file')
															echo '<img src="'.DIR_WS_IMAGES.'icons/icon_file.gif" alt="" title="Datei" />';
														else {
															echo '<img src="'.DIR_WS_IMAGES.'icons/icon_database.gif" alt="" title="Datenbank" /> ';
															echo '<a onclick="if(!confirm(\'Wollen Sie die Box \”'.$box->fields['box_title'].'\” wirklich löschen?\')) return false;" href="'.href_link('box_manager.php', 'delete='.$box->fields['box_name']).'">
															<img src="'.DIR_WS_IMAGES.'icons/cross.png" alt="" title="Box l&ouml;schen" /></a>';
														}
														if($box->fields['box_name'] == 'categories')
															echo ' <a href="'.href_link('box_manager.php', 'do=duplicate_cat').'" title="Kategoriebox duplizieren"><img src="'.DIR_WS_IMAGES.'icons/document-copy.png" alt="" title="Kategoriebox duplizieren" />';
														if(strstr($box->fields['box_name'], 'categories_') && is_numeric(substr($box->fields['box_name'], 11)))
															echo '<a href="'.href_link('box_manager.php', 'delete='.$box->fields['box_name']).'"><img src="'.DIR_WS_IMAGES.'icons/cross.png" alt="" title="Box l&ouml;schen" /></a>';
													?>
												</td>
											</tr>
										<?php
										$i++;
										$box->MoveNext();
										} ?>
									</table>
								<?php } elseif((isset($_GET['action'])) && (($_GET['action'] == 'new_box') || ($_GET['action'] == 'edit_new_box'))) {

									$dd[] = array ('id' => '1', 'text' => YES);
									$dd[] = array ('id' => '0', 'text' => NO);

									if($_GET['action'] == 'edit_new_box') {
										$new_box = $db->db_query("SELECT
																		b.id, 
																		b.box_name,
																		b.position,
																		b.sort_id,
																		b.in_blog,
																		b.status AS box,
																		bn.status AS bname,
																		b.group_ids
																	FROM
																		".TABLE_BOXES." b,
																		".TABLE_BOXES_NAMES." bn
																	WHERE
																		bn.box_name = b.box_name
																	AND
																		bn.language_id = '".$_SESSION['languages_id']."'
																	AND
																		b.box_name = '".$_GET['name']."' ");
										
										$box_styles = $db->db_query("SELECT
																			border_color,
																			background_content,
																			color_content,
																			background_head,
																			color_head
																		FROM
																			".TABLE_BOXES_STYLES."
																		WHERE
																			box_name = '".$_GET['name']."'");
									}
									echo  draw_form('new_box', 'box_manager.php', getMenuID('box_manager'), 'post', 'id="database_box"');
									?>
										<script type="text/javascript">
											$('#database_box').submit(function(){
												if($('.box_int_name').val() != '') {
													return true;
												}
												alert('Geben Sie einen eindeutigen Begriff für die interne Bezeichnung an!');
												$('.box_int_name').focus().css('border','2px solid #b20000');
												return false;
											});
										</script>
										<table width="100%">
											<tr>
												<td colspan="2">
													<table width="100%" class="dataTable" >
														<tr>
															<td>
															Rahmenfarbe:<br />
																<?php echo draw_input_field('border_color',($box_styles->fields['border_color']!='')? $box_styles->fields['border_color'] : '','maxlength="7" size="7" class="multiple" style="text-align:center;background:'.$box_styles->fields['border_color'].'"'); ?>
															</td>
															<td>
																Hintergrundfarbe der Box:<br />
																<?php echo draw_input_field('background_content',($box_styles->fields['background_content']!='')? $box_styles->fields['background_content'] : '','maxlength="7" size="7" class="multiple" style="text-align:center;background:'.$box_styles->fields['background_content'].'"'); ?>
															</td>
															<td>
																Schriftfarbe Content:<br />
																<?php echo draw_input_field('color_content',($box_styles->fields['color_content']!='')? $box_styles->fields['color_content'] : '','maxlength="7" size="7" class="multiple" style="text-align:center;background:'.$box_styles->fields['color_content'].'"'); ?>
															</td>
															<td>
																Hintergrund Titel:<br />
																<?php echo draw_input_field('background_head',($box_styles->fields['background_head']!='')? $box_styles->fields['background_head'] : '','maxlength="7" size="7" class="multiple" style="text-align:center;background:'.$box_styles->fields['background_head'].'"'); ?>
															</td>
															<td class="last">
																Schriftfarbe Titel:<br />
																<?php echo draw_input_field('color_head',($box_styles->fields['color_head']!='')? $box_styles->fields['color_head'] : '','maxlength="7" size="7" class="multiple" style="text-align:center;background:'.$box_styles->fields['color_head'].'"'); ?>
															</td>
														</tr>
													</table>
												</td>
											</tr>
											<tr class="dataTableHeadingRow">
												<th class="dataTableHeadingContent" align="left" height="20">Box Einstellungen</th>
												<th class="dataTableHeadingContent" align="center" height="20">Name / Inhalt</th>
											</tr>
											<tr>
												<td valign="top" width="30%">
													<table class="dataTable" width="100%">
														<tr>
															<td>Position: </td>
															<td><?php echo draw_pull_down_menu('box_position', $position_array, $new_box->fields['position'], 'style="width:60px"'); ?></td>
														</tr>
														<tr>
															<td>Sortierung: </td>
															<td><?php echo draw_input_field('box_sort_id',$new_box->fields['sort_id'],'size="3" style="text-align:center;width:60px"'); ?></td>
														</tr>
														<tr>
															<td>Box aktiv: </td>
															<td><?php echo draw_pull_down_menu('box_status',$dd,($_GET['action'] == 'new_box'?1:$new_box->fields['box']), 'style="width:60px"'); ?></td>
														</tr>
														<tr>
															<td>Titel an: </td>
															<td><?php echo draw_pull_down_menu('box_name_status',$dd,($_GET['action'] == 'new_box'?1:$new_box->fields['bname']), 'style="width:60px"'); ?></td>
														</tr>
														<tr>
															<td>Im Blog anzeigen: </td>
															<td><?php echo draw_pull_down_menu('box_in_blog', $dd, ($_GET['action'] == 'new_box'?1:$new_box->fields['in_blog']), 'style="width:60px"'); ?></td>
														</tr>
														<tr>
															<td>interne Bezeichnung:</td>
															<td><?php
																if(!empty($new_box->fields['box_name']))
																	echo $new_box->fields['box_name'].draw_hidden_field('box_int_name', $new_box->fields['box_name']);
																else
																	echo draw_input_field('box_int_name','','class="box_int_name"');
															?></td>
														</tr>
														<?php
															if(GROUP_CHECK=='true') {
																$boxes_array = get_customers_statuses(); ?>	
																<tr>
																	<td style="border: 1px solid #b20000; border-width: 1px 0 1px 1px; background:#FFE9A6" valign="top">
																		<?php echo ENTRY_CUSTOMERS_STATUS; ?>
																	</td>
																	<td style="border: 1px solid #b20000; border-width: 1px 1px 1px 0; background:#FFE9A6">
																		<?php
																		
																		for ($i=0; $n=sizeof($boxes_array), $i<$n; $i++) {
																			if(strstr($new_box->fields['group_ids'],'c_'.$boxes_array[$i]['id'].'_g'))
																				$checked = 'checked ';
																			else
																				$checked = '';
		
																			echo '<input type="checkbox" name="groups[]" value="'.$boxes_array[$i]['id'].'"'.$checked.' /> '.$boxes_array[$i]['text'].'<br />';
																		}
																		
																		?>
																	</td>
																</tr>
															<?php
															}
														?>
													</table>
												</td>
												<td valign="top" width="70%">
													<table width="100%">
														<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
															if($_GET['action'] == 'edit_new_box')
																$name = $db->db_query("SELECT
																							box_title,box_desc
																						FROM
																							".TABLE_BOXES_NAMES."
																						WHERE
																							box_name = '".$_GET['name']."'
																						AND
																							language_id = '".$languages[$i]['id']."' ");
														?>
															<tr>
																<td width="100" style="border:0" nowrap="nowrap">
																	<?php
																		echo '<img src="../lang/'. $languages[$i]['directory'].'/'.$languages[$i]['image'].'" alt="'.$name->fields['box_title'].'" /> ';
																		echo $languages[$i]['name'].': ';
																	?>
																</td>
																<td style="border:0">
																	<?php echo draw_input_field('box_title_'.$languages[$i]['id'], $name->fields['box_title']); ?>
																</td>
															</tr>
															<tr>
																<td colspan="2">
																	<?php echo wysiwyg('new_box_'.$languages[$i]['id'], $name->fields['box_desc']); ?>
																</td>
															</tr>
														<?php } ?>
													</table>
												</td>
											</tr>
											<tr>
												<td colspan="2" align="right">
													<?php
														if($name->_numOfRows)
															echo draw_hidden_field('save','edit_new_box');
														else
															echo draw_hidden_field('save','new_box');
													?>
													<button type="submit" class="button">
														<span class="button_disk-black"><?php echo BUTTON_SAVE; ?></span>
													</button>
													<button type="submit" name="apply_box" class="button">
														&Uuml;bernehmen
													</button>
													<a class="button" href="box_manager.php?menu=<?php echo $_GET['menu']; ?>">
														<?php echo BUTTON_CANCEL?>
													</a>
													<?php echo draw_hidden_field('name',$_GET['name']); ?>
												</td>
											</tr>
										</table>
									</form>
								<?php } elseif($_GET['action'] == 'edit_box') { ?>
									<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>" name="edit_box">
										<table class="dataTable" width="100%">
											<tr class="dataTableHeadingRow">
												<th class="dataTableHeadingContent" align="left" height="20">Box Titel</th>
												<th class="dataTableHeadingContent" align="center" height="20">Position</th>
												<th class="dataTableHeadingContent" align="center" height="20">Sortierung</th>
												<th class="dataTableHeadingContent" align="center" height="20">Box aktiv?</th>
												<th class="dataTableHeadingContent" align="center" height="20">Titel an?</th>
												<th class="dataTableHeadingContent" align="center" height="20">im Blog anzeigen?</th>
												<th class="dataTableHeadingContent" align="right" height="20" class="last"><?php echo get_help('3','Position im Template');?></th>
											</tr>
											<?php
												$box = $db->db_query("SELECT
																			b.id AS id,
																			b.box_name AS box_name,
																			b.position AS position,
																			b.sort_id AS sort_id,
																			b.status AS box,
																			b.in_blog,
																			b.group_ids,
																			b.box_type AS type,
																			bn.status AS bname,
																			bn.box_title AS title
																		FROM
																			".TABLE_BOXES." b,
																			".TABLE_BOXES_NAMES." bn
																		WHERE
																			b.box_name = '".$_GET['name']."'
																		AND
																			bn.box_name = '".$_GET['name']."' ");


												$box_styles = $db->db_query("SELECT
																					border_color,
																					background_content,
																					color_content,
																					background_head,
																					color_head
																				FROM
																					".TABLE_BOXES_STYLES."
																				WHERE
																					box_name = '".$_GET['name']."'");

												$dd[] = array ('id' => '1', 'text' => YES);
												$dd[] = array ('id' => '0', 'text' => NO);

												?>
												<tr>
													<td>
														<table width="100%">
															<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
																$name = $db->db_query("SELECT box_title FROM ".TABLE_BOXES_NAMES." WHERE box_name = '".$_GET['name']."' AND language_id = '".$languages[$i]['id']."' "); 	?>
																<tr>
																	<td width="1" style="border:0">
																		<?php echo '<img src="../lang/'. $languages[$i]['directory'].'/'.$languages[$i]['image'].'" alt="'.$name->fields['box_title'].'" /> '; ?>
																	</td>
																	<td style="border:0">
																		<?php echo draw_input_field('box_name_'.$languages[$i]['id'], $name->fields['box_title'],'style="width:200px"'); ?>
																	</td>
																</tr>
															<?php } ?>
														</table>
													</td>
													<td align="center" valign="middle">
														<?php echo draw_pull_down_menu('box_position', $position_array, $box->fields['position'],'style="width:auto"'); ?>
													</td>
													<td align="center" valign="middle">
														<?php echo draw_input_field('box_sort_id',($box->fields['sort_id']!='')? $box->fields['sort_id'] : '0','size="3" style="text-align:center;width:auto"'); ?>
													</td>
													<td align="center" valign="middle">
														<?php echo draw_pull_down_menu('box_status',$dd,$box->fields['box'],'style="width:auto"'); ?>
													</td>
													<td class="last" align="center" valign="middle">
														<?php echo draw_pull_down_menu('in_blog', $dd, $box->fields['in_blog'],'style="width:auto"'); ?>
													</td>
													<td class="last" align="center" valign="middle">
														<?php echo draw_pull_down_menu('box_name_status',$dd,$box->fields['bname'],'style="width:auto"'); ?>
													</td>
													<td nowrap="nowrap" class="last">
														<button type="submit" class="button">
															<span class="button_disk-black"><?php echo BUTTON_SAVE; ?></span>
														</button> 
														<a class="button" href="box_manager.php?<?php echo getMenuID('box_manager'); ?>">
															<span class="button_door-open-in-black"><?php echo BUTTON_CANCEL?></span>
														</a>
														<?php echo draw_hidden_field('name',$_GET['name']).draw_hidden_field('save','file_box'); ?>
													</td>
												</tr>
										</table>
										<table width="100%" class="dataTable" >
											<tr>
												<?php
													if(GROUP_CHECK=='true') {
														$boxes_array = get_customers_statuses();
														?>
														<td>
															<table width="100%">
																<tr>
																	<td style="border: 1px solid #b20000; border-width: 1px 0 1px 1px; background:#FFE9A6" valign="top">
																		<?php echo ENTRY_CUSTOMERS_STATUS; ?>
																	</td>
																	<td style="border: 1px solid #b20000; border-width: 1px 1px 1px 0; background:#FFE9A6">
																		<?php
																		for ($i=0; $n=sizeof($boxes_array), $i<$n; $i++) {
																			if(strstr($box->fields['group_ids'],'c_'.$boxes_array[$i]['id'].'_g'))
																				$checked = 'checked ';
																			else
																				$checked = '';
		
																			echo '<input type="checkbox" name="groups[]" value="'.$boxes_array[$i]['id'].'"'.$checked.' /> '.$boxes_array[$i]['text'].'<br />';
																		}
																		?>
																	</td>
																</tr>
															</table>
														</td>
													<?php
													}
												?>
												<td>
												Rahmenfarbe:<br />
													<?php echo draw_input_field('border_color',($box_styles->fields['border_color']!='')? $box_styles->fields['border_color'] : '','maxlength="7" size="7" class="multiple" style="text-align:center;background:'.$box_styles->fields['border_color'].'"'); ?>
												</td>
												<td>
													Hintergrundfarbe der Box:<br />
													<?php echo draw_input_field('background_content',($box_styles->fields['background_content']!='')? $box_styles->fields['background_content'] : '','maxlength="7" size="7" class="multiple" style="text-align:center;background:'.$box_styles->fields['background_content'].'"'); ?>
												</td>
												<td>
													Schriftfarbe Content:<br />
													<?php echo draw_input_field('color_content',($box_styles->fields['color_content']!='')? $box_styles->fields['color_content'] : '','maxlength="7" size="7" class="multiple" style="text-align:center;background:'.$box_styles->fields['color_content'].'"'); ?>
												</td>
												<td>
													Hintergrund Titel:<br />
													<?php echo draw_input_field('background_head',($box_styles->fields['background_head']!='')? $box_styles->fields['background_head'] : '','maxlength="7" size="7" class="multiple" style="text-align:center;background:'.$box_styles->fields['background_head'].'"'); ?>
												</td>
												<td class="last">
													Schriftfarbe Titel:<br />
													<?php echo draw_input_field('color_head',($box_styles->fields['color_head']!='')? $box_styles->fields['color_head'] : '','maxlength="7" size="7" class="multiple" style="text-align:center;background:'.$box_styles->fields['color_head'].'"'); ?>
												</td>
											</tr>
										</table>
									</form>
								<?php } ?>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</div>
<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php');